package com.eduction.modules.system.dao;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.eduction.bean.ExpertGroupMapBean;
import com.eduction.common.dbutil.DbHelper;
import com.eduction.modules.system.entity.Expert;

@Repository
public class ObservationRepository {

	@Autowired
	private DbHelper dbHelper;
	@Autowired
	private ObservationDao observationDao;
	
	/**
	 * 根据专家编号查询信息
	 * @throws SQLException 
	 * 
	 */
	public Expert queryExpertByAccount(String account) throws SQLException{
		String sql = "SELECT a.* FROM t_expert as a where a.s_expert_code = ?";
		return dbHelper.getBean(sql, Expert.class, account);
	}
	
	/**
	 * 查询专家与组的关系
	 * @throws SQLException 
	 */
	public ExpertGroupMapBean queryExpertGroupMap(String expertId) throws SQLException{
		String sql = "SELECT a.p_id as pid, a.s_expert_id as s_expertId, a.s_group_id as s_groupId, a.s_identity as s_identity,b.s_name as expertName,"
				+ " b.s_strutss as s_strutss, c.s_name as s_groupName, c.s_type as s_type, c.s_state as s_state"
				+ " FROM t_expert_group_map as a"
				+ " LEFT JOIN t_expert as b ON a.s_expert_id = b.p_id"
				+ " LEFT JOIN t_group as c ON a.s_group_id = c.p_id"
				+ " where 1=1 AND c.s_state != '3' and a.s_expert_id = ?";
		//c.s_type = '2'
		return dbHelper.getBean(sql, ExpertGroupMapBean.class, expertId);
	}
	
	/**
	 * 查询专家信息
	 */
	public Expert queryExpertInfo(String pid){
		Expert e = observationDao.findOne(pid);
		return e;
	}
	
	/**
	 * 保存专家信息
	 */
	public void saveExpertInfo(Expert e){
		observationDao.save(e);
	}
}
